
import java.util.*;

public class Order implements Iterable<OrderItem>{
    private ArrayList<OrderItem> items=new ArrayList<OrderItem>();
    public Order(){ }
    public void addItem(OrderItem orderItem){
        items.add(orderItem);
    }
    public void removeItem(OrderItem orderItem){
        items.remove(orderItem);
    }
    public Iterator<OrderItem> iterator(){
        Iterator<OrderItem> b=items.iterator();
        return b;
    }
    public OrderItem getItem(Product product){
        for(Iterator<OrderItem>iterator=this.items.iterator();iterator.hasNext();){
           OrderItem item=(OrderItem)iterator.next();
           if(item.getProduct().equals(product)){
              return item;
           }
       }
       return null;
    }
    public int getNumberOfItems(){
        return items.size();
    }
    public double getTotalCost(){
        double sum=0.0D;
        for(Iterator<OrderItem>c=items.iterator();c.hasNext();) {
            sum = c.next().getValue() + sum;
        }
        return sum;
    }

}
